/*
 * @Author: 计都 3038199036@qq.com
 * @Date: 2024-09-19 17:36:32
 * @LastEditors: 计都 3038199036@qq.com
 * @LastEditTime: 2024-09-23 19:29:04
 * @FilePath: \vuePDF\src\getFiles.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export async function getPDFs() {
    const basePath = 'http://47.94.209.183/notes/';// 相对于服务器根目录下的public目录中的notes文件夹的路径
    const response = await fetch(basePath, { method: 'GET' });
    console.log(response,'9999');
    
    const text = await response.text();
    // 这里简单解析返回的文本内容来获取文件夹和文件信息（如果是HTML目录结构）
    const lines = text.split('\n');
    const pdfsByFolder = {};
    lines.forEach((line) => {
        if (line.includes('.pdf')) {
            const parts = line.split('/');
            const folder = parts[parts.length - 2];
            const pdfName = parts[parts.length - 1];
            const pdfPath = basePath + '/' + line;
            if (!pdfsByFolder[folder]) {
                pdfsByFolder[folder] = [];
            }
            pdfsByFolder[folder].push({ name: pdfName, path: pdfPath });
        }
    });
    const result = [];
    for (const folder in pdfsByFolder) {
        result.push({
            folder,
            pdfs: pdfsByFolder[folder]
        });
    }
    console.log(result+"this is fucking bloody hell result !"+JSON.stringify(result));
    
    return result;
}

